﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;

namespace PeisongWeb
{
    public partial class buyer_orderItemList :buyerPage
    {
        protected int orderid
        {
            get
            {
                int tmp;
                try { tmp = Convert.ToInt32(ViewState["orderid"]); }
                catch { tmp = 0; }
                return tmp;
            }
            set
            { ViewState["orderid"] = value; }
        }

        protected int type
        {
            get
            {
                int tmp;
                try { tmp = Convert.ToInt32(ViewState["type"]); }
                catch { tmp = 0; }
                return tmp;
            }
            set
            { ViewState["type"] = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["order"] != null)
                {
                    if (Library.Number.IsIntPositive(Request.QueryString["order"]))
                    {
                        orderid = Convert.ToInt32(Request.QueryString["order"]);
                    }
                }
                if (Request.QueryString["type"] != null)
                {
                    if (Library.Number.IsIntPositive(Request.QueryString["type"]))
                    {
                        type = Convert.ToInt32(Request.QueryString["type"]);
                    }
                }
                if (orderid != 0)
                {
                    if (hasPermission("BB", 1, orderid, "orderId"))
                    {
                        rptBind();
                        getDetails();
                    }
                    else
                    {
                        Library.Script.ClientMsgUrl("没有权限！", "buyer_index.html");
                        return;
                    }
                }
            }
        }
        void rptBind()
        {
            StringBuilder where = new StringBuilder();
            where.Append("orderid=" + orderid);
            where.Append("and companyId=" + logic.customer.getCompanyId()); //add by Jurgen 2010-1-26 17:47
            DataSet ds = logic.orderItem.select(where.ToString(), "oiid", 100, 1);
            //AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
            rpt_list.DataSource = ds.Tables[1];
            rpt_list.DataBind();
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            rptBind();
        }

        void getDetails()
        {
            StringBuilder where = new StringBuilder();
            where.Append("orderid=" + orderid);
            DataSet ds = logic.order.select(where.ToString(), "orderid", 1, 1);
            DataRow dr = ds.Tables[1].Rows[0];
            lbl_orderNo.Text = dr["orderNo"].ToString();
            lbl_status.Text = dr["statusName"].ToString();
            lbl_receiveUser.Text = dr["contact"].ToString();
            lbl_receiveTel.Text = dr["contactMobile"].ToString() + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + dr["contactPhone"].ToString();
            lbl_receiveAddress.Text = dr["areaName"].ToString() + dr["address"].ToString();
            lbl_orderDt.Text = dr["orderDt"].ToString();
            lbl_amount.Text = String.Format("{0:F2}", dr["amount"]).ToString();
            lbl_receiveDt.Text = dr["receiveDt"].ToString();
            lbl_orderNote.Text = dr["note"].ToString() + "&nbsp;";
        }
    }
}
